package com.xsyj.awati.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xsyj.awati.IconAction;
import com.xsyj.awati.R;
import com.xsyj.awati.activity.ArtificialBaseNewActivity;
import com.xsyj.awati.activity.ChannelWaterSupplyActivity;
import com.xsyj.awati.entry.IconBean;
import com.yuang.library.base.BaseFragment;

import org.angmarch.views.NiceSpinner;

import java.util.Arrays;
import java.util.List;

/**
 * 作者：KD on 2021/12/3
 * <p>
 * 10:47
 */
public class HomeFragment extends BaseFragment {

    private RecyclerView iconRecycleView;
    private ArtificialBaseAdapter artificialBaseAdapter;
    private List<String> statueCodeList = Arrays.asList("阿瓦提县", "第一大队", "第二大队", "第三大队");
    private NiceSpinner mapSpinner;

    @Override
    public int getLayoutId() {
        return R.layout.home_layout;
    }

    @Override
    public void initUI(View view, Bundle savedInstanceState) {
        List<IconBean> icon = IconAction.getIcon();
        iconRecycleView = view.findViewById(R.id.iconRecycleView);
        mapSpinner = view.findViewById(R.id.mapSpinner);
        mapSpinner.attachDataSource(statueCodeList);
        artificialBaseAdapter = new
                ArtificialBaseAdapter(R.layout.icon_item_layout);
        iconRecycleView.setLayoutManager(new GridLayoutManager(mContext, 4));
        iconRecycleView.setAdapter(artificialBaseAdapter);
        artificialBaseAdapter.setNewData(icon);
        artificialBaseAdapter.setOnItemChildClickListener((adapter, viewItem, position) -> {
            switch (position) {
                case 0:
                    break;
                case 1:
                    Intent intent = new Intent(mContext, ChannelWaterSupplyActivity.class);
                    startActivity(intent);
                    break;
                case 2:
                    break;
                case 3:
                    break;
                case 4:
                    break;
                case 5:
                    break;
                case 6:
                    Intent intentArt = new Intent(mContext, ArtificialBaseNewActivity.class);
                    startActivity(intentArt);


                    break;
                case 7:
                    break;
                case 8:
                    break;
                default:
                    break;
            }
        });
    }


    static class ArtificialBaseAdapter extends BaseQuickAdapter<IconBean, BaseViewHolder> {
        public ArtificialBaseAdapter(int layoutResId) {
            super(layoutResId);
        }

        @Override
        protected void convert(BaseViewHolder helper, IconBean item) {
            helper.setImageResource(R.id.icon, item.getIcon());
            helper.setText(R.id.title, item.getTitle());
            helper.addOnClickListener(R.id.linerLayout);
        }
    }


}
